package com.googlecode.tracey.id;

import static com.googlecode.tracey.id.TraceyIdValue.traceyIdValue;
import static java.util.UUID.randomUUID;

public class TraceyId {
    private static final ThreadLocal<TraceyIdValue> ids = new InheritableThreadLocal<TraceyIdValue>();

    public static TraceyIdValue set(TraceyIdValue id) {
        ids.set(id);
        return id;
    }

    public static boolean hasValue() {
        return ids.get() != null && ids.get().hasValue();
    }

    public static TraceyIdValue get() {
        return ids.get();
    }

    public static TraceyIdValue makeOneUp() {
        return set(traceyIdValue(randomUUID().toString()));
    }

    public static void clear() {
        ids.set(null);
    }
}
